package com.cloud.system.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cloud.system.api.entity.SysResources;
import com.cloud.system.common.utils.BaseMapperHelper;

public interface SysResourcesMapper extends BaseMapperHelper<SysResources> {

	@Update("update sys_resource set delete_flag = 1 where res_code like ${resCode}")
	void deleteResources(String resCode);

	@Select("select distinct t1.res_id, t1.res_type_id, t1.res_title, t1.res_url, t1.display_icon, t1.display_class,t1.display_order, "
			+ "t1.senior_id from sys_resources t1 , role_resources t2, human_role t3 "
			+ "where t1.res_id = t2.res_id and t2.role_id = t3.role_id and t3.human_id = #{humanId} and t1.sys_id = #{sysId} "
			+ "and t1.delete_flag = 0 and t2.res_type > 0 order by t1.display_order , t1.res_id")
	@Results({ @Result(property = "resId", column = "res_id", javaType = Long.class),
			@Result(property = "resTypeId", column = "res_type_id", javaType = Integer.class),
			@Result(property = "resTitle", column = "res_title", javaType = String.class),
			@Result(property = "resUrl", column = "res_url", javaType = String.class),
			@Result(property = "displayIcon", column = "display_icon", javaType = String.class),
			@Result(property = "displayClass", column = "display_class", javaType = String.class),
			@Result(property = "seniorId", column = "senior_id", javaType = Long.class) })
	List<SysResources> listResourcesBySysIdAndHumanId(@Param("sysId") long sysId, @Param("humanId") long humanId);
}